import  axios from 'axios'
import store from '@/store';
// 二次封装axios  加拦截器,
let instance = axios.create({
    // 路径重构 baseURL 在每一路径前面拼接/api
    baseURL:'/api',
    timeout:5000
})
// 拦截器 
instance.interceptors.request.use((config)=>{

    if(store.state.shopcart.userTempId){
        config.headers.userTempId = store.state.shopcart.userTempId;
    }
    if(store.state.user.token){
        config.headers.token = store.state.user.token
    }
    return config
});
instance.interceptors.response.use(
    (response)=>{
        return response.data
    },
    (error)=>{
        Promise.reject(error)
    }
);
export default instance;